<h1>Role Management</h1>


<div id="select_new">
<?php echo form_tag('index',array('method'=>'get'))?>
<?php echo link_to('Add New Role',array('controller'=>'admin/roles' ))?> |
Get Details For: <?php echo select_tag('id',options_for_select($all_roles, (int) @$_REQUEST['id']))?>
<?php echo submit_tag('Edit')?>
<?php echo end_form_tag()?>
</div>

<?php echo error_messages_for('roles')?>

<?php
    if ( !$roles->is_loaded() )
    {
?>
    <h3>Add Role</h3>      
    <?php echo form_tag('index',array('validation'=>true))?>
    <?php echo hidden_field_tag('action','add_role')?>
    <?php include load_template('_form.php')?>
    <div id='submit'><?php echo submit_tag('Add Role')?></div>
    <?php echo end_form_tag()?>
  
<?php } else { ?>
    
    <?php echo content_tag('h2', "Managing Role: <span style='color:red'>".$roles->get('role_name')."</span>") ?>
    <div id='tabsmenu'>
        <ul id='tabs'>
            <li><a href="#tab1">Edit Role details</a></li>
            <li><a href="#tab2">Users who have this role</a></li>
            <li><a href="#tab3">Permissions for this role</a></li>
        </ul>
    </div>
 
<div id="tab1" class='tab-page'>
    <h3>Details</h3>
    <div class='yui-g'>
        <div class='yui-u first'>
            <?php echo form_tag('index',array('id'=>'role-edit-form'))?>
            <?php echo hidden_field_tag('action','edit_role')?>
            <?php include load_template('_form.php')?>
            <?php echo hidden_field('roles','id')?>
            <div id='submit'><?php echo submit_tag('Edit Role')?></div>
            <?php echo end_form_tag()?>
            <?php echo validate_form('role-edit-form') ?>
        </div>
        <div class='div-delete yui-u'>
            <?php echo  form_tag('delete') ?>
            <?php echo  hidden_field_tag('id',$roles->get('id')) ?>
            <?php echo  hidden_field_tag('action','delete') ?>
            <span style='color:red;font-weight:bold'>Delete This Role?</span>
            <?php echo  submit_tag('Delete Role',array('confirm'=>'Are you sure you want to delete this role?','class'=>'submit_delete')) ?>
            <?php echo  end_form_tag() ?>    
        </div>
    </div>                    
</div>
    
<div id="tab2" class='tab-page'>
        <h3>Users</h3>
        <div class='user_roles' style='width:350px;'>
        <?php echo form_remote_tag(array('controller'=>'admin/roles' ,'action'=>'modify_role_users'),
                                    array(
                                        'name'=>'user_roles',
                                        'update'=>'success_messages',
                                        'before'=>"selectAll('users')",
                                        'complete'=>"toggle_success();",
                                        )
                                );
         ?>
        <?php echo hidden_field_tag('role_id', $roles->get('id'))?>
        <?php echo select_transfer('users[]', array_diff($all_users,$role_users), $role_users)?>  
        <p><?php echo submit_tag('Modify Roles')?></p>
        <?php echo end_form_tag()?>
       </div>
    </div>
    
<div id="tab3" class='tab-page'>
    <h3>Permissions</h3>
    <div id='role_permissions'>
        <p>Permissions can be set per user, and they are also inherited from roles.</p>

    <?php include load_template('_permissions.php');?>
            <br style='clear:both'>
    </div>
</div>
<?php } ?>


    <h2>Role Crib Sheet:</h2>
    <div class='section'>
    <?php
    if (is_array($role_descriptions)) {
        foreach($role_descriptions as $arole)
        {
            echo content_tag('p', 
                            content_tag('b',$arole->get('role_name')).' '.
                            $arole->get('role_description')
                            );
        }
    }
    ?>
    
    </div>
